﻿namespace Cuce.ReportingServices
{
    using System;
    using SSRSWS;

    /// <summary>
    /// Wrapper for Integrated Reporting Service Reports
    /// </summary>
    /// <remarks>This class will allow for intergated testing of Reporting Service reports.
    /// All that it will test is that with valid parameters, the report renders. 
    /// This testing framework doesn't test for correctness of reports results</remarks>
    public class IntergratedTestWrapper : TestWrapper
    {

        /// <summary>
        /// Initializes a new instance of the <see cref="IntergratedTestWrapper"/> class.
        /// </summary>
        /// <param name="reportService">The report service.</param>
        public IntergratedTestWrapper(IReportingService reportService) : base(reportService) 
        { }

        /// <summary>
        /// Tests the report, but calling for the report to be rendered and
        /// determinig if its been successful or not
        /// </summary>
        /// <param name="reportName">Name of the report.</param>
        /// <param name="parameterList">The parameter list.</param>
        /// <returns>If the report was rendered or not</returns>
        public ReportResult TestReport(ReportName reportName, ParameterValue[] parameterList)
        {
            //test all parameters are entered
            if (string.IsNullOrEmpty(ReportServer))
                throw new ArgumentException("Report Server not set", "ReportServer");

            if (reportName == null)
                throw new ArgumentException("Report Name is null", "reportName");

            if (parameterList == null)
                throw new ArgumentException("parameterList is null", "parameterList");

            try
            {
                RenderReport(reportName, parameterList, OutputType.CSV);

            }
            catch (ReportException ef)
            {
                if (ef.Warnings == null)
                    throw ef;
                else
                    return ReportResult.WARNINGS;
            }

            return ReportResult.PASS;
        }

        /// <summary>
        /// Tests the report, but calling for the report to be rendered and
        /// determinig if its been successful or not
        /// </summary>
        /// <param name="reportName">Name of the report.</param>
        /// <returns>If the report was rendered or not</returns>
        public ReportResult TestReport(ReportName reportName)
        {
            return TestReport(reportName, new ParameterValue[] { });
        }

    }
}
